package org.rcy.ruicingmarket.common.utils;

import java.util.UUID;

/**
 * @author RuicyWu
 * @Date 2021/10/2 13:19
 */
public class TokenUtils {

    /**
     * 生成token
     *
     * @param
     * @param
     * @param
     * @return
     */
    public static String getToken(Long id,String key) {
        return UUID.randomUUID().toString().replace("-","")+"_"+AESUtils.encrypt(id+"",key);
    }

    public static Long getIdFromToken(String token,String key) {
        String decryptToken = AESUtils.decrypt(token.substring(token.indexOf("_")+1,token.length()), key);
        Long id = Long.parseLong(decryptToken);
        return id;
    }

}
